package org.one.afternoon.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.one.afternoon.domain.User;
import org.one.afternoon.mapper.UserMapper;
import org.one.afternoon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean login(User user) {
        // 去数据库查找用户
        User getUser = userMapper.findUserByUsername(user.getUsername());
        if (getUser == null) {
            //用户不存在！
            return false;
        }
        if (!getUser.getPassword().equals(user.getPassword())) {
            //用户名或者密码错误！
            return false;
        }
        // 设定登录成功消息
        userMapper.updateOnline(1, user.getUsername());

        return true;
    }

    @Override
    public boolean logout(String username) {
        userMapper.updateOnline(0, username);
        return true;
    }

    @Override
    public Integer queryTdy(Integer time) {
        return userMapper.findTdy(time);
    }

    @Override
    public Integer queryNew(Integer time) {
        return userMapper.findNew(time);
    }
}
